<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ExamedEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $key;
    public $exam;


    public function __construct($key, $exam)
    {
        $this->key = $key;
        $this->exam = $exam;
    }

    /**
     * 找到该事件应该在哪个频道播出.
     *
     * @return Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('exam.' . $this->key);
    }

    /**
     * 返回数据
     *
     * @return string[]
     */
    public function broadcastWith(): array
    {
        return ['message' => '考试结束'];
    }
}
